package kim.artemis.rpc.core.common.enums;

import cn.hutool.core.util.StrUtil;
import kim.artemis.rpc.core.registry.ServiceRegistry;
import kim.artemis.rpc.core.registry.ZookeeperServiceRegistry;
import lombok.Getter;

/**
 * 服务注册方式枚举
 * @author Wq.
 */
public enum ServiceRegistryEnum {

    Zookeeper(ZookeeperServiceRegistry.class);

    @Getter
    private Class<? extends ServiceRegistry> serviceRegistry;

    ServiceRegistryEnum(Class<? extends ServiceRegistry> serviceRegistry) {
        this.serviceRegistry = serviceRegistry;
    }

    public static ServiceRegistryEnum match(String name, ServiceRegistryEnum defaultServiceRegistry){
        if (StrUtil.isNotBlank(name)) {
            for (ServiceRegistryEnum item: ServiceRegistryEnum.values()) {
                if (item.name().equals(name)) {
                    return item;
                }
            }
        }
        return defaultServiceRegistry;
    }
}
